import { defineStore } from 'pinia'
import { ref } from 'vue'
import { DialogQueue } from '@/utils/dialogQueue'

export const useMessageDialogStore = defineStore('messageDialog', () => {
    // 状态
    const dialogQueue = new DialogQueue()
    const currentDialog = ref(null)

    // 显示消息对话框
    const show = (messageText, titleText) => {
        return dialogQueue.show({
            onLoaded: () => {
                currentDialog.value = {
                    title: titleText,
                    message: messageText
                }
            }
        })
    }

    // 隐藏消息对话框
    const hide = () => {
        dialogQueue.hide()
    }

    return {
        isVisible: dialogQueue.isVisible,
        title: () => currentDialog.value?.title || '',
        message: () => currentDialog.value?.message || '',
        show,
        hide,
        getQueueLength: dialogQueue.getQueueLength.bind(dialogQueue),
        clearQueue: dialogQueue.clearQueue.bind(dialogQueue)
    }
}) 